{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31mFailed to start the Kernel. \n",
      "\u001b[1;31mAttributeError: 'SelectIOLoop' object has no attribute 'asyncio_loop'. \n",
      "\u001b[1;31mView Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
     ]
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "# Define the URL for the Flask app\n",
    "# app_url = 'http://localhost:5000'  # Update the URL as needed\n",
    "app_url = \"https://6bb0-128-237-82-20.ngrok-free.app\"\n",
    "\n",
    "# Define the image file to upload\n",
    "image_file = {'image': open('step_2_image_left_camera.png', 'rb')}\n",
    "prompt1 = \"<image>0</image>Describe every objects in the image and their spatial relationship, and describe their backgrounds\"\n",
    "prompt2 = \"<image>0</image><grounding>list all objects in the image <phrase>\"\n",
    "goal = \"woman\"\n",
    "threshold=0.05\n",
    "\n",
    "try:\n",
    "    # Send a POST request with the image file\n",
    "    response = requests.post(app_url, files=image_file, data={'text_inputs': prompt1, 'grounding_prompt':prompt2, 'goal':goal,'threshold':threshold})\n",
    "    data = response.json()\n",
    "    print(data)\n",
    "    if 'result' in data:\n",
    "        print(\"Extracted Text:\", data['result'])\n",
    "    elif 'error' in data:\n",
    "        print(\"Error:\", data['error'])\n",
    "    if 'found' in data:\n",
    "        print(f\"Found {goal}:\", data['found'])\n",
    "    # if 'all_objects' in data:\n",
    "    #     print(f\"Found all objects:\", data['all_objects'])\n",
    "\n",
    "except requests.exceptions.RequestException as e:\n",
    "    print(\"Request Error:\", e)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "kosmos2",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.2"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
